package com.mc.dao.Impl;

import com.mc.VO.MatchVO;
import com.mc.bean.Student;
import com.mc.dao.MatchVODao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangcf
 * @version 1.0
 * @Description 赛事团队视图类数据访问接口实现类
 * @date 2023/2/15 18:56
 */
public class MatchVODaoImpl extends BaseDao implements MatchVODao {

    @Override
    public List<MatchVO> findByMid(int mid) {
        List<MatchVO> matchVOList = new ArrayList<>();
        try {
            regist();
            connection();
            getPst("select apply.`mid`,team.`teamid`,team.`teamname`,apply.matchcode from apply,team where apply.`teamid`=team.`teamid` and apply.`mid`=?");
            pstmt.setInt(1,mid);
            getRs();
            while (rs.next()){
                MatchVO matchVO=new MatchVO(rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4));
                matchVOList.add(matchVO);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            close();
        }
        return matchVOList;
    }

    @Override
    public List<Student> findByMidInfoStu(int mid) {
        List<Student> studentList = new ArrayList<>();
        try {
            regist();
            connection();
            getPst("select student.sid from apply,st,student where apply.`teamid`=st.`teamid`and st.`sid`=student.`sid` and apply.`mid`=?");
            pstmt.setInt(1,mid);
            getRs();
            while (rs.next()){
                Student student=new Student(rs.getInt(1));
                studentList.add(student);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            close();
        }
        return studentList;
    }
}
